NOTE: This Technical Note has been
retired. Please see the Technical Notes
page for current documentation.![]() ![]() |
NoteThe following code makes heavy use of features of the Macintosh Programmer's Workshop. It also assumes a basic familiarity with the standard Sample program included with MPW. The Pascal code (which is here only as an example implementation of the mechanism) is presented as only those sections which differ from Sample.p. The assembly language code also includes MPW-only features, such as record templates. Some of these are explained in TN.PT.Signals. In addition, since the order in which parameters to various routines are passed is critical, special care will have to be taken in writing interfaces for use with C. It is probably best to declare them as Pascal in the C source. ConceptsBasically, we create a code resource of type CUST with an entry point at the beginning which takes several parameters on the stack; this code is reached via a dispatching routine which is written in assembly language. The data passed on the stack to this dispatcher includes:
Other parameters may be added (as long as they are pushed on the stack before
the required ones) if desired. Since these extra parameters would always
have to be included in any calls to a given package, it might be more
convenient to use the application global space area which is accessed through
the TemplateYour application must contain the following global data and procedure declarations to support this model:
You must also assemble CustomInit and CustomCall and link them with into your application. The custom package itself can be written in any language which can produce stand-alone code. The example
Note that this example is somewhat contrived; you probably wouldn't "externalize" the code for finding a word or sequence of characters like this. This is an idealized situation. More realistic uses would be: to add-on special routines to a database to perform custom calculations or the like; allow for localization when code is required (and hooks aren't already provided); let documents carry around code which may vary among software versions, etc. so that older documents would be able to work alongside the new ones, etc. What it doesWe simply add a new menu to the sample program which allows Find bycharacters or word. We just pass the menu item to the package and let it do the finding; it then calls back to the application dispatch routine to highlight text or display the "not found" message. The Pascal source for the example application appears first:
ReferencesDownloadables
|
Developer Documentation | Technical Q&As | Development Kits | Sample Code |